package control;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.ControlDB;

@WebServlet("/QueryTitleList")
public class QueryTitleList extends HttpServlet{
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setContentType("text/plain;charset=utf-8");

		String inputCategory = req.getParameter("category");
		if (inputCategory == null) {
			ControlDB ctrl = new ControlDB();
			PrintWriter out = resp.getWriter();
			out.print(ctrl.getTitleList());
			out.close();
		} else {
			ControlDB ctrl = new ControlDB();
			PrintWriter out = resp.getWriter();
			out.print(ctrl.getTitleList(inputCategory));
			out.close();
		}
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO 自动生成的方法存根
		doPost(req, resp);
	}
}
